package org.hs.phd.odi.tracking.tracker.particlefilter.transition;

import org.hs.phd.common.randomnumbers.RandomNumberGenerator;

public class SecondOrderAutoRegressiveTransitionHelper {

	private final double a1;
	private final double a2;
	private final double b0;

	public SecondOrderAutoRegressiveTransitionHelper(double a1, double a2, double b0) {
		this.a1 = a1;
		this.a2 = a2;
		this.b0 = b0;
	}

	public double transitionMinMaxTrim(double initialValue, double prevValue, double currentValue, RandomNumberGenerator noise, double min, double max) {
		return minMaxTrim(transition(initialValue, prevValue, currentValue, noise), min, max);
	}

	public double transition(double initialValue, double prevValue, double currentValue, RandomNumberGenerator noise) {
		return a1 * (currentValue - initialValue) + a2 * (prevValue - initialValue) + b0 * noise.nextRandom() + initialValue;
	}

	public double minMaxTrim(double value, double min, double max) {
		return Math.max(min, Math.min(max, value));
	}

}
